<template>
  <div id="main">
    <el-card class="itemcard" v-for="ai in lists" :key="ai.id">
      <h3 align="center">{{ ai.user.name }}</h3>
      <div class="block">
        <el-image :src="ai.photo" title="AI截取图片" alt="图片加载失败" />
      </div>
      <el-input
        v-model="ai.message"
        style="margin: 10px 0"
        placeholder="请输入分析信息"
      ></el-input>
      <div class="tool">
        <el-button @click="updateai(ai.id, ai.message)" class="browserButton"
          >保存</el-button
        >
        <el-button @click="open(ai.id)" class="deleteButton">删除</el-button>
      </div>
    </el-card>
  </div>
</template>

<script>
import { getAllAiPhoto, deleteAiById, updateAi } from "@/api/ai";
export default {
  data() {
    return {
      lists: [],
    };
  },
  created() {
    getAllAiPhoto().then((res) => {
      this.lists = res.data.list;
    });
  },
  methods: {
    open(id) {
      this.$confirm("此操作将永久删除该文件, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          deleteAiById(id).then((res) => {
            this.$message.success("删除成功");
            getAllAiPhoto().then((res) => {
              this.lists = res.data.list;
            });
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    updateai(id, message) {
      updateAi(id, message).then((res) => {
        this.$message.success("提交成功");
        getAllAiPhoto().then((res) => {
          this.lists = res.data.list;
        });
      });
    },
  },
};
</script>

<style  scoped>
.tool {
  display: flex;
  flex-direction: row;
  justify-content: space-around;
}
.el-image {
  width: 100%;
  height: auto;
}
.itemcard {
  width: 30%;
  margin-left: 2.5%;
  margin-top: 1%;
  border-radius: 10px;
  box-shadow: 0.1em 0.1em 0.3em rgb(65, 65, 65, 0.5);
}
#main {
  width: 100%;
  display: flex;
  flex-direction: row;
  justify-content: flex-start;
  flex-wrap: wrap;
}
.block {
  width: 100%;
}
</style>
